package pers.course.week9;

import java.util.*;

class Student implements Comparable<Student> {
    private double Grade;
    private String Name;
    private int Age;
    public Student(String name, int age, double grade) {
        this.Grade = grade;
        this.Name = name;
        this.Age = age;
    }
    @Override
    public int compareTo(Student o) {
        if (this.Grade > o.Grade) {
            return (int) (o.Grade - this.Grade);
        } else if (this.Grade < o.Grade) {
            return (int) (o.Grade - this.Grade);
        } else {
            return this.Age - o.Age;
        }
    }
    public String getName() {
        return Name;
    }
}

class NameSort implements Comparator {
    @Override
    public int compare(Object o1, Object o2) {
        return ((Student)o1).getName().compareTo(((Student)o2).getName());
    }
}

public class StudentSort {
    public static void main(String[] args) {
        Student[] students = new Student[]{
                new Student("liusan",20,90.0),
                new Student("lisi",22,90.0),
                new Student("wangwu",20,99.0),
                new Student("sunliu",20,100.0)
        };
        Arrays.sort(students);
        StringBuilder sb1 = new StringBuilder();
        for (Student student:students) {
            sb1.append(student.getName()).append(", ");
        }
        String str1 = sb1.toString();
        System.out.println(str1.substring(0, str1.length() - 2));
        LinkedList<Student> list = new LinkedList<>();
        list.add(new Student("liusan",20,90.0));
        list.add(new Student("lisi",22,90.0));
        list.add(new Student("wangwu",20,99.0));
        list.add(new Student("sunliu",20,100.0));
        Collections.sort(list,new NameSort());
        StringBuilder sb2 = new StringBuilder();
        for (Student student : list) {
            sb2.append(student.getName()).append(", ");
        }
        String str2 = sb2.toString();
        System.out.println(str2.substring(0, str2.length() - 2));
    }
}
